//
//  WJTabBarPlusController.m
//  JerryIos
//
//  Created by jerrywang on 2018/2/5.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJTabBarPlusController.h"
#import "WJTabBarPlus.h"
#import "WJTab1Controller.h"
#import "WJTab2Controller.h"
#import "WJTab3Controller.h"
#import "WJTab4Controller.h"
#import "WJNavigationController.h"

@interface WJTabBarPlusController ()

@end

@implementation WJTabBarPlusController

+(void) load {
    //获取哪个类下的UITabBarItem
    UITabBarItem *tabBarItem = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    //设置按钮选中时标题的颜色
    //创建一个描述文本属性的字典
    NSMutableDictionary *attrsColor = [NSMutableDictionary dictionary];
    attrsColor[NSForegroundColorAttributeName] = [UIColor blackColor];
    [tabBarItem setTitleTextAttributes:attrsColor forState:UIControlStateSelected];
    
    //设置字体尺寸。字体尺寸只有在正常状态下，才有效果
    NSMutableDictionary *attrsFont = [NSMutableDictionary dictionary];
    attrsFont[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [tabBarItem setTitleTextAttributes:attrsFont forState:UIControlStateNormal];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加子控制器
    [self setupChildViewController];
    
    // 设置TabBar上的内容
    [self setupTabBarButton];
    
    // 自定义TabBar
    [self setupCustomTabBar];
    
}

-(void) setupChildViewController {
    //Tab1控制器
    WJTab1Controller *tab1Controller = [[WJTab1Controller alloc] init];
    WJNavigationController *navTab1Controller = [[WJNavigationController alloc] initWithRootViewController:tab1Controller];
    [self addChildViewController:navTab1Controller];
    
    //Tab2控制器
    WJTab2Controller *tab2Controller = [[WJTab2Controller alloc] init];
    WJNavigationController *navTab2Controller = [[WJNavigationController alloc] initWithRootViewController:tab2Controller];
    [self addChildViewController:navTab2Controller];
    
    //Tab3控制器
    WJTab3Controller *tab3Controller = [[WJTab3Controller alloc] init];
    WJNavigationController *navTab3Controller = [[WJNavigationController alloc] initWithRootViewController:tab3Controller];
    [self addChildViewController:navTab3Controller];
    
    //Tab4控制器
    WJTab4Controller *tab4Controller = [[WJTab4Controller alloc] init];
    WJNavigationController *navTab4Controller = [[WJNavigationController alloc] initWithRootViewController:tab4Controller];
    [self addChildViewController:navTab4Controller];
    
}

-(void) setupTabBarButton {
    //tab1按钮
    UINavigationController *navTab1Controller = self.childViewControllers[0];
    navTab1Controller.tabBarItem.title = @"精华";
    navTab1Controller.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_essence_normal"];
    navTab1Controller.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_essence_selected"];
    
    //tab2按钮
    UINavigationController *navTab2Controller = self.childViewControllers[1];
    navTab2Controller.tabBarItem.title = @"新帖";
    navTab2Controller.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_new_normal"];
    navTab2Controller.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_new_selected"];
    
    //tab3按钮
    UINavigationController *navTab3Controller = self.childViewControllers[2];
    navTab3Controller.tabBarItem.title = @"关注";
    navTab3Controller.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_friendTrends_normal"];
    navTab3Controller.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_friendTrends_selected"];
    
    //tab4按钮
    UINavigationController *navTab4Controller = self.childViewControllers[3];
    navTab4Controller.tabBarItem.title = @"我";
    navTab4Controller.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_me_normal"];
    navTab4Controller.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_me_selected"];
    
}

-(void) setupCustomTabBar {
    WJTabBarPlus *tabBar = [[WJTabBarPlus alloc] init];
    tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_light"];
    //
    [self setValue:tabBar forKey:@"tabBar"];
}

@end

